package com.elecbook.content.api.controller;

import com.elecbook.base.dto.PageDTO;
import com.elecbook.base.result.Result;
import com.elecbook.content.model.dto.CommentJudgeSubmitDTO;
import com.elecbook.content.model.dto.CommentjudgePQuery;
import com.elecbook.content.model.dto.CommnetJudgePageDTO;
import com.elecbook.content.model.po.Commentjudge;
import com.elecbook.content.service.CommentjudgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/commentJudge")
public class CommentJudgeController {
    @Autowired
    private CommentjudgeService commentjudgeService;

    @PostMapping("/submit")
    public Result<Commentjudge> sumbitJudge(@RequestBody CommentJudgeSubmitDTO dto) {
        Commentjudge commentjudge = commentjudgeService.submitJudge(dto);
        return Result.success(commentjudge);
    }

    @PostMapping("/page")
    public Result<PageDTO<Commentjudge>> page(@RequestBody CommnetJudgePageDTO pageDTO) {
        PageDTO<Commentjudge> pageResult = commentjudgeService.queryCommentJudgePage(pageDTO);
        return Result.success(pageResult);
    }


       /*
    管理员生成方法
    */

    @PostMapping("/op/save")
    Result<Commentjudge> save(@RequestBody Commentjudge commentjudge) {
        Commentjudge res = commentjudgeService.saveCommentjudge(commentjudge);
        return Result.success(res);
    }

    @DeleteMapping("/op/{id}")
    Result<String> delete(@PathVariable Long id) {
        commentjudgeService.removeById(id);
        return Result.success();
    }

    @GetMapping("/op/{id}")
    Result<Commentjudge> get(@PathVariable Long id) {
        Commentjudge res =  commentjudgeService.getById(id);
        return Result.success(res);
    }

    @PutMapping("/op/update")
    Result<Commentjudge> update(@RequestBody Commentjudge commentjudge) {
        Commentjudge res =  commentjudgeService.updateCommentjudgeById(commentjudge);
        return Result.success(res);
    }

    @PostMapping("/op/page")
    Result<PageDTO<Commentjudge>> page(@RequestBody CommentjudgePQuery commentjudgeQuery) {
        PageDTO<Commentjudge> pageResult = commentjudgeService.pageQuery(commentjudgeQuery);
        return Result.success(pageResult);
    }
}
